const chalk = require('chalk')
const msgPath = process.argv[2]
const msg = require('fs')
  .readFileSync(msgPath, 'utf-8')
  .trim()//获取提交信息

const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release|build time)(\(.+\))?: .{1,50}/

if (!commitRE.test(msg)) {
  console.log()
  console.error(
    `  ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
      `无效的提交消息格式`
    )}\n\n` +
    chalk.red(
      `  自动生成更新日志需要正确的提交消息格式 例如:\n`
    ) +
    `  ${chalk.yellow('type(XXXXX):空格需求号_XXXXXXXXXXXXX')}\n` +
    `  ${chalk.green('feat(模块名): v6.2.8_提交信息简短的描述')}\n` +
    `  ${chalk.green('fix(模块名): #106308 禅道里的 bug 标题')}\n`
  )
  process.exit(1)
}